

clear 
set scheme lean2, permanent
global pm = char(177)
set more off

gl date = c(current_date)
if c(os) == "MacOSX" gl user "/Users/`c(username)'"
else if c(os) == "Windows" gl user "C:\Users\\`c(username)'"
else if c(os) == "Unix" gl user "/usr/`c(username)'"
di "$user

set graphics on  

global path_data_processed "\data\processed"
global path_output "\data\output"

 
clear all
set more off

cd "$path_data_processed"
use "experimentRNall.dta", clear

cd "$path_output"
 

			   loc experiments "posterior unemp_prob unemp_county_prob z_profits z_fin_prosp jobinsecurity"

			   keep if posterior!=.
			     
				 
		
				 

foreach var of varlist republican democrat finlit_index{
gen mis_`var' = `var'==.
replace `var'=0 if `var'==.
}

replace log_income=0 if inc_NR==1
global controls age agesq female log_income inc_NR atleast_bachelor midwest south west republican democrat finlit_index mis_republican mis_finlit_index
	   
			   
preserve

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' {

    loc ++columns
    qui eststo col`columns': reg x y

}

restore


/* Statistics */

loc colnum = 1
loc colnames ""




foreach choice in `experiments' {


***Main: complete sample


    qui ivreg2 `choice'  treatment $controls, r
    sigstar treatment, prec(3)
    estadd loc thisstat4 = "`r(bstar)'": col`colnum'
    estadd loc thisstat5 = "`r(sestar)'": col`colnum'
	qui sum `choice'
    estadd loc thisstat7 = r(N): col`colnum'

	
***main: follow-up sample
	
    qui ivreg2 `choice'  treatment $controls if posterior_f!=. , r
    sigstar treatment, prec(3)
    estadd loc thisstat12 = "`r(bstar)'": col`colnum'
    estadd loc thisstat13 = "`r(sestar)'": col`colnum'
	qui sum `choice'  if posterior_f!=.
    estadd loc thisstat15 = r(N): col`colnum'	

*** follow-up
	

    qui ivreg2 `choice'_f  treatment $controls if posterior_f!=. , r
    sigstar treatment, prec(3)
    estadd loc thisstat20 = "`r(bstar)'": col`colnum'
    estadd loc thisstat21 = "`r(sestar)'": col`colnum'
	qui sum `choice'  if posterior_f!=.
    estadd loc thisstat23 = r(N): col`colnum'		
      

    loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"

}
	
	
	
 

	

	


loc rowlabels " " " "{\bf Panel A: Main complete sample}" " " "Recession: High" " " " " "Observations" " "   "\hline" "{\bf Panel B: Main follow-up sample}" " " "Recession: High" "  " " " "Observations" " "   "\hline" "{\bf Panel C: Follow-up}" " " "Recession: High" "  " " " "Observations" " "   "\hline" " "   "
loc rowstats ""

forval i = 1/23 {
    loc rowstats "`rowstats' thisstat`i'"
}

esttab * using "table4_persistence.tex", replace cells(none) booktabs nonotes nomtitles compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
	mgroups("\shortstack{Posterior:\\Recession\\(percent)}" "\shortstack{National\\unemployment\\(percent)}"  ///
  "\shortstack{County\\unemployment\\(percent)}" "\shortstack{Firm\\profits\\(categorical)}" "\shortstack{Household\\financial\\prospects}"  ///
   "\shortstack{Personal\\unemployment\\(percent)}", pattern(1 1 1 1 1 1 1 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

	
	
eststo clear	







